﻿using System;
using System.Collections.Generic;
using System.Text;
using CDE_Model;

namespace XML_Indexing.AnvilIndex
{
    public class AnvilIndex : IXMLIndex
    {
        private Element _node;

        public Element Node
        {
            get { return _node; }
            set { _node = value; }
        }

        #region IXMLIndex Members

        public bool CreateIndex(Element _ele)
        {
            _node = _ele;
            return true;
        }

        public IXMLIndex FindChild(string genericIdentifier)
        {
            foreach (Element e in _node.Children)
            {
                if (e.GenericIdentifier.Equals(genericIdentifier))
                {
                    AnvilIndex newIndex = new AnvilIndex();
                    newIndex.CreateIndex(e);
                    return newIndex;
                }
            }

            return null;
        }

        public bool CreateIndex(List<Element> _eleList)
        {
            throw new NotImplementedException();
        }

        public bool CreateIndex(Document _doc)
        {
            throw new NotImplementedException();
        }

        public bool CreateIndex(Collection _col)
        {
            throw new NotImplementedException();
        }

        public List<IXMLIndex> FindChildren(string genericIdentifier)
        {
            List<IXMLIndex> indexes = new List<IXMLIndex>();
            foreach (Element e in _node.Children)
            {
                if (e.GenericIdentifier.Equals(genericIdentifier))
                {
                    AnvilIndex newIndex = new AnvilIndex();
                    newIndex.CreateIndex(e);
                    indexes.Add(newIndex);
                }
            }

            return indexes;
        }

        #endregion
    }
}
